# -*- coding: utf-8 -*-
# @Author : y
# @Date   : 2021/6/15
# @File   : EG42_EntSecurityFundOweCheck.py
# @E-mail : yantao@bbdservice.com

'''eof
name:申请企业是否有社保欠费记录
code:EG42_EntSecurityFundOweCheck
tableName:
columnName:
groups:企业通用模块
dependencies:FGW_DSJ
type:常用指标
datasourceType:在线指标
description:
eof'''
import sys
import pandas as pd
import json
from datetime import datetime
import time


def format_data(tableName):
    try:
        eg = FGW_DSJ.get("data").get(tableName)
        return eg if isinstance(eg, list) else [{}]
    except:
        return [{}]

def get_date_list():
    try:
        now = datetime.now()
        aaa = [(now + pd.tseries.offsets.DateOffset(months=i)).strftime('%Y%m%d') for i in [-36, 0]]
        return aaa
    except:
        return None


def get_result():
    '''
    申请企业是否有社保欠费记录
    Factor=企业参保信息（qycbInfo）中欠费状态（qfbz）=="欠费"
    '''
    null_type_list = ['', ' ', None, 'null', 'Null', 'NULL', '/', '-', '--']
    intercept_cause = '欠费'
    try:
        alter_list = format_data("qycbInfo")
        if alter_list == [{}]:
            return u'缺失值'
        else:
            if len(alter_list) >= 1:
                factor = []
                for i in alter_list:
                    qfbz = i.get("qfbz")
                    if qfbz not in null_type_list :
                        if qfbz ==intercept_cause :
                            return 1
                        else:
                            factor.append(0)
                return 0 if len(factor) > 0 else u'缺失值'
            else:
                return 0
    except:
        return u'缺失值'


if __name__ == "__main__":
    # file_obj = open(r'../data/DAS/Past3YearPatentedInventionsNum/FGW_DSJ.json', encoding='utf-8', mode='r')
    file_obj = open(r'./FGW_DSJ.json', encoding='utf-8', mode='r')
    content = file_obj.read()
    FGW_DSJ = json.loads(content, strict=False)
    aa = get_result()
    print(aa)

# result = get_result()
